package com.sh.promise;


import com.sh.promise.executor.RejectExecutor;
import com.sh.promise.executor.ResolveExecutor;

public class PromiseExecutor implements ResolveExecutor, RejectExecutor {
    private Promise promise;
    protected PromiseExecutor(Promise promise){
        this.promise = promise;
    }

    @Override
    public void resolve(final Object args) {
        promise.transformStatus(Status.FULFILLED,args);
    }

    @Override
    public void reject(final Throwable args) {
        promise.transformStatus(Status.REJECTED,args);
    }

    /**
     * 获取通过new Promise.Builder().externalInput(Object externalInput)方法注入的参数。
     * @return
     */
    public Object getExternalInput(){
        return this.promise.getExternalInput();
    }

    /**
     * 获内部promise的执行结果。通过new Promise.Builder().promise(promise1)指定的promise1的执行结果
     * @return
     */
    public Object getPromiseInput(){
        return this.promise.getPromiseInput();
    }
}
